# coding=utf-8
from django.http import HttpResponse
from django.shortcuts import render_to_response
from view_contexts import *


def get_homepage(request):
    return HttpResponse("Main page")


def get_materials_list(request, type = 'all', author = 'all'):
    """
    Get materials by type and author filters
    """
    context = MaterialListContext()
    for i in xrange(5):
        preview = create_material(type, author, i)
        context.materials_list.append(preview)
    return render_to_response("materials_list.html", {'context': context})


def create_material(type, author, index):
    material = MaterialPreview()
    material.author_name = author
    material.title = 'Title%d' % index
    material.type = type
    material.gtp_link = 'gtp_link%d' % index
    return material


def get_material(request, type, author, title):
    context = MaterialContext()
    context.author_name = author
    context.content = "Some chords \n\n Some text"
    context.title = title
    context.type = type
    return render_to_response("material.html", {'context': context})


def get_authors_list(request):
    """
    Get authors list
    """
    context = AuthorListContext()
    for i in xrange(5):
        author = AuthorPreview()
        author.name = 'Author Name %d' % i
        author.description = "Short description"
        context.author_list.append(author)
    return render_to_response("authors_list.html", {'context': context})


def get_author(request, author_name):
    context = AuthorContext()
    context.name = author_name
    context.image_link = 'img_%s.jpg' % author_name
    context.description = "Full description"
    for i in xrange(3):
        link = WebLink()
        link.url = 'www.%s%d.ru' % (author_name, i)
        link.type = '%d' % i
        link.description = 'Site №%d' % i
        link.image = 'link%d.jpg' % i
        link.title = link.description
        context.links.append(link)
    return render_to_response("author.html", {'context': context})


def get_favorites(request):
    return HttpResponse("Favorites")

